# CMake 最低版本号要求
cmake_minimum_required (VERSION 2.8)
# 项目信息
project (pyfree-monitor)
#
if(WIN32)
    message(STATUS "windows compiling...")
    add_definitions(-D_PLATFORM_IS_WINDOWS_)
	set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MT")
  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MTd")
  set(WIN_OS true)
else(WIN32)
    message(STATUS "linux compiling...")
    add_definitions( -D_PLATFORM_IS_LINUX_)
    add_definitions("-Wno-invalid-source-encoding")
	  # add_definitions("-O2")
    set(UNIX_OS true)
    set(_DEBUG true)
    
endif(WIN32)

#
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/../demo-project/monitor)

# 指定源文件的目录,并将名称保存到变量
SET(source_h
    #func
    ${PROJECT_SOURCE_DIR}/../common/pfunc.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_code.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_format.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_str.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_ip.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_time.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_v.h
    ${PROJECT_SOURCE_DIR}/../common/pfunc_print.h
    #software info
    ${PROJECT_SOURCE_DIR}/../common/License.h
    ${PROJECT_SOURCE_DIR}/../common/ostype.h
    ${PROJECT_SOURCE_DIR}/../common/version.h
    ${PROJECT_SOURCE_DIR}/../common/appexitio.h
    #func
    ${PROJECT_SOURCE_DIR}/../common/Log.h
    ${PROJECT_SOURCE_DIR}/../common/Mutex.h
    ${PROJECT_SOURCE_DIR}/../common/queuedata.h
    ${PROJECT_SOURCE_DIR}/../common/queuedata_single.h
    ${PROJECT_SOURCE_DIR}/../common/DiskSpace.h
    ${PROJECT_SOURCE_DIR}/../common/spaceMgr.h
    ${PROJECT_SOURCE_DIR}/../common/strTrim.h
    ${PROJECT_SOURCE_DIR}/../common/strchange.h
    ${PROJECT_SOURCE_DIR}/../common/File.h
    #code
    ${PROJECT_SOURCE_DIR}/../common/Base64.h
    ${PROJECT_SOURCE_DIR}/../common/SHA1.h
    ${PROJECT_SOURCE_DIR}/../common/HMACSHA1.h
    ${PROJECT_SOURCE_DIR}/../common/HMAC_SHA1.h
    ${PROJECT_SOURCE_DIR}/../common/cJSON.h
    #conf
    ${PROJECT_SOURCE_DIR}/conf/conf_alarm.h
    ${PROJECT_SOURCE_DIR}/conf/conf_app.h
    ${PROJECT_SOURCE_DIR}/conf/conf_dev.h
    ${PROJECT_SOURCE_DIR}/conf/conf_pis.h
    ${PROJECT_SOURCE_DIR}/conf/conf_plan.h
    ${PROJECT_SOURCE_DIR}/conf/conf_pmap.h
    ${PROJECT_SOURCE_DIR}/conf/conf_read.h
    ${PROJECT_SOURCE_DIR}/conf/conf_war.h
    ${PROJECT_SOURCE_DIR}/conf/datadef.h
    ${PROJECT_SOURCE_DIR}/conf/dtypedef.h
    #business data
    ${PROJECT_SOURCE_DIR}/conf/business_def.h
    ${PROJECT_SOURCE_DIR}/conf/horizontal_data.h
    ${PROJECT_SOURCE_DIR}/conf/appconf_data.h
    ${PROJECT_SOURCE_DIR}/conf/hashmap.h
    #tcp-socket-gather
    ${PROJECT_SOURCE_DIR}/net_socket/socket_cache_thread.h
    ${PROJECT_SOURCE_DIR}/net_socket/socket_gather_read.h
    ${PROJECT_SOURCE_DIR}/net_socket/socket_gather_write.h
    ${PROJECT_SOURCE_DIR}/net_socket/socket_gather.h
    ${PROJECT_SOURCE_DIR}/net_socket/socket_private_acl.h
    ${PROJECT_SOURCE_DIR}/net_socket/socket_srv_acl.h
    #tcp-sokcet-local-client
    ${PROJECT_SOURCE_DIR}/net_socket_client/socket_local_read.h
    ${PROJECT_SOURCE_DIR}/net_socket_client/socket_local_write.h
    ${PROJECT_SOURCE_DIR}/net_socket_client/socket_local.h
    #verify
    ${PROJECT_SOURCE_DIR}/verify_control/verifyforcontrol.h
    ${PROJECT_SOURCE_DIR}/verify_control/verifyforcontrolcache.h
    #dispatch
    ${PROJECT_SOURCE_DIR}/strategy/strategy.h
    ${PROJECT_SOURCE_DIR}/strategy/delay_plan_thread.h
    ${PROJECT_SOURCE_DIR}/strategy/plan_thread.h
    ${PROJECT_SOURCE_DIR}/strategy/alarm_thread.h
    ${PROJECT_SOURCE_DIR}/strategy/timeUpInfo.h
    #sqlite-record
    ${PROJECT_SOURCE_DIR}/record_sqlite/record_queue.h
    ${PROJECT_SOURCE_DIR}/record_sqlite/sqlite_io.h
    ${PROJECT_SOURCE_DIR}/record_sqlite/sqlite_record.h
    #waring event create
    ${PROJECT_SOURCE_DIR}/waring/waringEventThread.h
    #msg for aliyun
    ${PROJECT_SOURCE_DIR}/msg/msg_to_aliyun_by_acl.h
    #email
    ${PROJECT_SOURCE_DIR}/email/email.h
    #iot to aliyun
    ${PROJECT_SOURCE_DIR}/iot_aliyun/aliyun_iot_func.h
    ${PROJECT_SOURCE_DIR}/iot_aliyun/consumer_aliyun.h
    ${PROJECT_SOURCE_DIR}/iot_aliyun/producer_aliyun.h
    ${PROJECT_SOURCE_DIR}/iot_aliyun/iot_to_aliyun.h
    #mqtt
    ${PROJECT_SOURCE_DIR}/mqttc/mqttFunc.h
    ${PROJECT_SOURCE_DIR}/mqttc/py_mqtt.h
    ${PROJECT_SOURCE_DIR}/mqttc/producer_mqtt.h
    ${PROJECT_SOURCE_DIR}/mqttc/consumer_mqtt.h
    ${PROJECT_SOURCE_DIR}/mqttc/io_mqtt.h
    #weather
    ${PROJECT_SOURCE_DIR}/weather/weather_http.h
    #
    ${PROJECT_SOURCE_DIR}/src/appinfo.h
  )
  
SET(source_cpp
    #func
    ${PROJECT_SOURCE_DIR}/../common/pfunc.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_code.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_format.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_str.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_ip.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_time.cpp
    ${PROJECT_SOURCE_DIR}/../common/pfunc_v.cpp
    #
    ${PROJECT_SOURCE_DIR}/../common/License.cpp
    ${PROJECT_SOURCE_DIR}/../common/version.cpp
    ${PROJECT_SOURCE_DIR}/../common/appexitio.cpp
    #
    ${PROJECT_SOURCE_DIR}/../common/Log.cpp
    ${PROJECT_SOURCE_DIR}/../common/Mutex.cpp
    ${PROJECT_SOURCE_DIR}/../common/DiskSpace.cpp
    ${PROJECT_SOURCE_DIR}/../common/spaceMgr.cpp
    ${PROJECT_SOURCE_DIR}/../common/strchange.cpp
    ${PROJECT_SOURCE_DIR}/../common/File.cpp
    #
    ${PROJECT_SOURCE_DIR}/../common/Base64.cpp
    ${PROJECT_SOURCE_DIR}/../common/SHA1.cpp
    ${PROJECT_SOURCE_DIR}/../common/HMACSHA1.cpp
    ${PROJECT_SOURCE_DIR}/../common/HMAC_SHA1.cpp
    ${PROJECT_SOURCE_DIR}/../common/cJSON.c
    #
    ${PROJECT_SOURCE_DIR}/conf/conf_read.cpp
    #
    ${PROJECT_SOURCE_DIR}/conf/business_def.cpp
    ${PROJECT_SOURCE_DIR}/conf/horizontal_data.cpp
    ${PROJECT_SOURCE_DIR}/conf/appconf_data.cpp
    ${PROJECT_SOURCE_DIR}/conf/hashmap.cpp
    #
    ${PROJECT_SOURCE_DIR}/net_socket/socket_cache_thread.cpp
    ${PROJECT_SOURCE_DIR}/net_socket/socket_gather_read.cpp
    ${PROJECT_SOURCE_DIR}/net_socket/socket_gather_write.cpp
    ${PROJECT_SOURCE_DIR}/net_socket/socket_gather.cpp
    ${PROJECT_SOURCE_DIR}/net_socket/socket_private_acl.cpp
    ${PROJECT_SOURCE_DIR}/net_socket/socket_srv_acl.cpp
    #
    ${PROJECT_SOURCE_DIR}/net_socket_client/socket_local_read.cpp
    ${PROJECT_SOURCE_DIR}/net_socket_client/socket_local_write.cpp
    ${PROJECT_SOURCE_DIR}/net_socket_client/socket_local.cpp
    #
    ${PROJECT_SOURCE_DIR}/verify_control/verifyforcontrol.cpp
    ${PROJECT_SOURCE_DIR}/verify_control/verifyforcontrolcache.cpp
    #
    ${PROJECT_SOURCE_DIR}/strategy/strategy.cpp
    ${PROJECT_SOURCE_DIR}/strategy/delay_plan_thread.cpp
    ${PROJECT_SOURCE_DIR}/strategy/plan_thread.cpp
    ${PROJECT_SOURCE_DIR}/strategy/alarm_thread.cpp
    ${PROJECT_SOURCE_DIR}/strategy/timeUpInfo.cpp
    #
    ${PROJECT_SOURCE_DIR}/record_sqlite/record_queue.cpp
    ${PROJECT_SOURCE_DIR}/record_sqlite/sqlite_io.cpp
    ${PROJECT_SOURCE_DIR}/record_sqlite/sqlite_record.cpp
    #
    ${PROJECT_SOURCE_DIR}/waring/waringEventThread.cpp
    #
    ${PROJECT_SOURCE_DIR}/msg/msg_to_aliyun_by_acl.cpp
    #
    ${PROJECT_SOURCE_DIR}/email/email.cpp
    #
    ${PROJECT_SOURCE_DIR}/iot_aliyun/aliyun_iot_func.cpp
    ${PROJECT_SOURCE_DIR}/iot_aliyun/consumer_aliyun.cpp
    ${PROJECT_SOURCE_DIR}/iot_aliyun/producer_aliyun.cpp
    ${PROJECT_SOURCE_DIR}/iot_aliyun/iot_to_aliyun.cpp
    #
    ${PROJECT_SOURCE_DIR}/mqttc/mqttFunc.cpp
    ${PROJECT_SOURCE_DIR}/mqttc/py_mqtt.cpp
    ${PROJECT_SOURCE_DIR}/mqttc/producer_mqtt.cpp
    ${PROJECT_SOURCE_DIR}/mqttc/consumer_mqtt.cpp
    ${PROJECT_SOURCE_DIR}/mqttc/io_mqtt.cpp
    #
    ${PROJECT_SOURCE_DIR}/weather/weather_http.cpp
    #
	  ${PROJECT_SOURCE_DIR}/src/main.cpp
  )
  
#头文件目录
include_directories(${PROJECT_SOURCE_DIR}/../common)
include_directories(${PROJECT_SOURCE_DIR}/../sqlite/include)
include_directories(${PROJECT_SOURCE_DIR}/../uuid/include)
include_directories(${PROJECT_SOURCE_DIR}/../iot_aliyun/sdk-impl)
include_directories(${PROJECT_SOURCE_DIR}/../mosquitto/include)
include_directories(${PROJECT_SOURCE_DIR}/conf)
include_directories(${PROJECT_SOURCE_DIR}/net_socket)
include_directories(${PROJECT_SOURCE_DIR}/net_socket_client)
include_directories(${PROJECT_SOURCE_DIR}/strategy)
include_directories(${PROJECT_SOURCE_DIR}/verify_control)
include_directories(${PROJECT_SOURCE_DIR}/record_sqlite)
include_directories(${PROJECT_SOURCE_DIR}/waring)
include_directories(${PROJECT_SOURCE_DIR}/msg)
include_directories(${PROJECT_SOURCE_DIR}/email)
include_directories(${PROJECT_SOURCE_DIR}/iot_aliyun)
include_directories(${PROJECT_SOURCE_DIR}/mqttc)
include_directories(${PROJECT_SOURCE_DIR}/weather)
include_directories(${PROJECT_SOURCE_DIR}/src)
#
include_directories(${PROJECT_SOURCE_DIR}/../acl-master/lib_acl/include)
include_directories(${PROJECT_SOURCE_DIR}/../acl-master/lib_acl_cpp/include)
include_directories(${PROJECT_SOURCE_DIR}/../acl-master/lib_protocol/include)

if (${UNIX_OS})

execute_process(COMMAND /bin/bash ../build.sh)

add_definitions(
  "-W"
  "-fPIC"
  "-Wall"
  # "-Wall -g"
  "-Werror"
  "-Wshadow"
  "-Wformat"
  "-Wpointer-arith"
  "-D_REENTRANT"
  "-D_USE_FAST_MACRO"
  "-Wno-long-long"
  "-Wuninitialized"
  "-D_POSIX_PTHREAD_SEMANTICS"
  "-DACL_PREPARE_COMPILE"
  "-Wno-unused-parameter"
  "-fexceptions"
  )
  set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")

link_directories(
  "${PROJECT_SOURCE_DIR}/../acl-master"
  "${PROJECT_SOURCE_DIR}/../sqlite/lib"
  "${PROJECT_SOURCE_DIR}/../uuid/lib"
  "${PROJECT_SOURCE_DIR}/../iot_aliyun/linux_lib/x64"
  "${PROJECT_SOURCE_DIR}/../mosquitto/lib_linux/x64"
)
# 指定生成目标
add_executable(pyfree-monitor ${source_h} ${source_cpp})
#link
target_link_libraries(pyfree-monitor 
  -lpthread -pthread -lz -lrt -ldl
  libacl_all.a
  libcsqlite.a
  libuuid.a
  libiot_sdk.a libiot_platform.a libiot_tls.a -Bstatic -lgcov
  -lmosquitto -lmosquittopp
)

endif()

if (${WIN_OS})

include_directories(${PROJECT_SOURCE_DIR}/../svc_common)

SET(source_cpp_win
  ${PROJECT_SOURCE_DIR}/../svc_common/WinSVC.cpp
)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819")

add_definitions(
  "-D_CRT_SECURE_NO_WARNINGS"
  "-D_WINSOCK_DEPRECATED_NO_WARNINGS"
  "-DNO_WARN_MBCS_MFC_DEPRECATION"
  "-DWIN32_LEAN_AND_MEAN"
)

link_directories(
  "${PROJECT_SOURCE_DIR}/../acl-master/dist/lib/win64"
  "${PROJECT_SOURCE_DIR}/../sqlite/lib"
  "${PROJECT_SOURCE_DIR}/../iot_aliyun/win_lib/x64"
  "${PROJECT_SOURCE_DIR}/../mosquitto/lib_win/x64"
  )

if (CMAKE_BUILD_TYPE STREQUAL "Debug")

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${PROJECT_SOURCE_DIR}/../demo-project/monitor)
# 指定生成目标
add_executable(pyfree-monitord ${source_h} ${source_cpp} ${source_cpp_win})

target_link_libraries(pyfree-monitord
  nafxcwd.lib
  LIBCMTD.lib
  lib_acl_vc2015d.lib lib_acl_cpp_vc2015d.lib lib_protocol_vc2015d.lib
  csqlited.lib
  iot_sdkd.lib
  mosquitto.lib mosquittopp.lib
)

else(CMAKE_BUILD_TYPE)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${PROJECT_SOURCE_DIR}/../demo-project/monitor)
# 指定生成目标
add_executable(pyfree-monitor ${source_h} ${source_cpp} ${source_cpp_win})

target_link_libraries(pyfree-monitor
  nafxcw.lib
  LIBCMT.lib
  lib_acl_vc2015.lib lib_acl_cpp_vc2015.lib lib_protocol_vc2015.lib
  csqlite.lib
  iot_sdk.lib
  mosquitto.lib mosquittopp.lib
)

endif (CMAKE_BUILD_TYPE)

endif()

